import { register } from '@/apis/user'
import { getToken, removeToken, setToken } from '@/utils/localstorage'
export default {
  namespaced: true,
  state: {
    token: getToken() || ''
  },
  mutations: {
    setToken (state, payload) {
      state.token = payload
      setToken(payload)
    },
    removeToken (state) {
      state.token = null
      removeToken()
    }
  },
  actions: {
    async register (ctx, payload) {
      const { data } = await register(payload)
      if (!data.body.toke) return
      ctx.commit('setToken', data.body.toke)
    },
    async logout (state) {
      state.commit('removeToken')
    }
  },
  getters: {}
}
